package com.nineclock.system.controller;

import com.nineclock.api.system.controller.SysCompanyUserControllerApi;
import com.nineclock.common.entity.Result;
import com.nineclock.dto.SysCompanyUserDTO;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/companyUser")
public class SysCompanyUserController implements SysCompanyUserControllerApi {
    @Autowired
    private SysCompanyUserService sysCompanyUserService;

    @GetMapping("/query")
    @Override
    public Result<List<SysCompanyUserDTO>> findCompanyUserByUserIdAndCompanyId(@RequestParam(value = "userId", required = false) Long userId
            , @RequestParam(value = "companyId", required = false) Long companyId) {
        List<SysCompanyUserDTO> sysCompanyUserDTOList = sysCompanyUserService.findCompanyUserByUserIdAndCompanyId(userId, companyId);

        return Result.success(sysCompanyUserDTOList);
    }
    @GetMapping("/queryById/{companyUserId}")
    @Override
    public Result<SysCompanyUserDTO> findCompanyUserById(@PathVariable("companyUserId") Long companyUserId) {
        SysCompanyUserDTO sysCompanyUserDTO = sysCompanyUserService.findCompanyUserById(companyUserId);
        return Result.success(sysCompanyUserDTO);
    }
// APP根据手机号查询员工信息
    @GetMapping("/queryone")
    @Override
    public Result<SysCompanyUserDTO> queryOne(String mobile) {
        SysCompanyUserDTO sysCompanyUserDTO = sysCompanyUserService.queryone(mobile);
        return Result.success(sysCompanyUserDTO);
    }
    // 获取当前企业所有员工
    @GetMapping("/queryAll")
    @Override
    public Result<List<SysCompanyUserDTO>> queryAllCompanyUsers() {
        List<SysCompanyUserDTO> list = sysCompanyUserService.queryAllCompanyUsers();
        return Result.success(list);
    }
    //根据企业ID查询企业的主管理员信息
    @GetMapping("/queryAdminByCompanyId")
    @Override
    public Result<SysCompanyUserDTO> queryAdminByCompanyId(Long companyId) {
        SysCompanyUserDTO sysCompanyUserDTO = sysCompanyUserService.queryAdminByCompanyId(companyId);
        return Result.success(sysCompanyUserDTO);
    }
}
